package com.monkey.bean;

import lombok.Data;

import java.io.Serializable;

@Data
public class Result<T> implements Serializable {

    private Boolean sucess;

    private Integer code;

    private String message;

    private T data;

    private Result() {
    }

    /**
     * 成功的无参方法
     * @return
     */
    public static Result ok(){
        Result result = new Result<>();
        result.setSucess(Boolean.TRUE);
        result.setCode(ResultCode.SUCESS);
        result.setMessage(ResultMessage.SUCESS);
        return result;
    }

    /**
     * 有参方法
     * @param resultCode
     * @param resultMessage
     * @return
     */
    public static Result ok(Integer resultCode,String resultMessage){
        Result result = new Result<>();
        result.setSucess(Boolean.TRUE);
        result.setCode(resultCode);
        result.setMessage(resultMessage);
        return result;
    }

    /**
     * 成功的有参参方法
     * @return
     */
    public static<T> Result ok(Integer resultCode,String resultMessage,T data){
        Result result = new Result<>();
        result.setSucess(Boolean.TRUE);
        result.setCode(resultCode);
        result.setMessage(resultMessage);
        result.setData(data);
        return result;
    }

    /**
     * 成功的方法
     * @param data 传入的数据
     * @param <T>
     * @return
     */
    public static<T> Result ok(T data){
        Result result = new Result<>();
        result.setSucess(Boolean.TRUE);
        result.setCode(ResultCode.SUCESS);
        result.setMessage(ResultMessage.SUCESS);
        result.setData(data);
        return result;
    }
    //-----------------------------失败的方法

    /**
     * 失败的无参方法
     * @return
     */
    public static Result fail(){
        Result result = new Result<>();
        result.setSucess(Boolean.FALSE);
        result.setCode(ResultCode.ERROR);
        result.setMessage(ResultMessage.ERROR);
        return result;
    }

    /**
     * 有参方法
     * @param resultCode
     * @param resultMessage
     * @return
     */
    public static Result fail(Integer resultCode,String resultMessage){
        Result result = new Result<>();
        result.setSucess(Boolean.FALSE);
        result.setCode(resultCode);
        result.setMessage(resultMessage);
        return result;
    }

    /**
     * 失败的有参参方法
     * @return
     */
    public static<T> Result fail(Integer resultCode,String resultMessage,T data){
        Result result = new Result<>();
        result.setSucess(Boolean.FALSE);
        result.setCode(resultCode);
        result.setMessage(resultMessage);
        result.setData(data);
        return result;
    }

    /**
     * 失败的方法
     * @param data 传入的数据
     * @param <T>
     * @return
     */
    public static<T> Result fail(T data){
        Result result = new Result<>();
        result.setSucess(Boolean.FALSE);
        result.setCode(ResultCode.ERROR);
        result.setMessage(ResultMessage.ERROR);
        result.setData(data);
        return result;
    }
}
